package com.pig4cloud.mall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.mall.product.dto.ProductParam;
import com.pig4cloud.mall.product.entity.Product;
import com.pig4cloud.mall.product.mapper.ProductMapper;
import com.pig4cloud.mall.product.service.ProductService;
import com.pig4cloud.pig.common.core.util.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 商品信息
 *
 * @author fangyu
 * @date 2020-12-26 19:40:58
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

	@Resource
	private ProductMapper productMapper;

	@Override
	public PageResult list(Page page, ProductParam productParam) {
		QueryWrapper<Product> wrapper = new QueryWrapper<>();
		if (StringUtils.isNotBlank(productParam.getName())) {
			wrapper.like("name", productParam.getName());
		}
		wrapper.orderByDesc("sort");
		return PageResult.buildPage(productMapper.selectPage(page, wrapper));
	}
}
